SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.DnnProduct_vw_ModulePermissions
AS
SELECT     
	MP.ModulePermissionID, 
	MP.ModuleID, 
	P.PermissionID, 
	MP.RoleID,
	CASE MP.RoleID
		when -1 then 'All Users'
		when -2 then 'Superuser'
		when -3 then 'Unauthenticated Users'
		else 	R.RoleName
	END AS 'RoleName',
	MP.AllowAccess, 
	MP.UserID,
	U.Username,
	U.DisplayName, 
	P.PermissionCode, 
	P.ModuleDefID, 
	P.PermissionKey, 
	P.PermissionName,
	MP.CreatedByUserID, 
    MP.CreatedOnDate, 
    MP.LastModifiedByUserID, 
    MP.LastModifiedOnDate
FROM dbo.DnnProduct_ModulePermission AS MP 
	LEFT OUTER JOIN dbo.DnnProduct_Permission AS P ON MP.PermissionID = P.PermissionID 
	LEFT OUTER JOIN dbo.DnnProduct_Roles AS R ON MP.RoleID = R.RoleID
	LEFT OUTER JOIN dbo.DnnProduct_Users AS U ON MP.UserID = U.UserID

GO
